import router from './router'
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css' // progress bar style
import getPageTitle from '@/utils/get-page-title'

NProgress.configure({ showSpinner: false }) // NProgres

// const whiteList = ['/login'] // no redirect whitelist
// 白名单就是无需登录，可以跳转查看的路由地址
router.beforeEach(async(to, from, next) => {
  NProgress.start()
  const token=window.sessionStorage.getItem('token')
if(token){
  if(to.path=='/login'){
    next('/')
  }else{
    next()
  }
}else{
  if(to.path=='/login' || to.path =='404'){
    next()
  }else{
    next('/login')
    NProgress.done()
  }
}
  
})

router.afterEach((to,from) => {
  document.title = getPageTitle(to.meta.title)
  NProgress.done()
})
